package com.darren.euc.dao.impl;


import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.darren.euc.dao.ManagerDao;
import com.darren.euc.entity.Manager;


@Repository
public class ManagerDaoImpl extends BaseDaoImpl<Manager, Integer> implements ManagerDao {
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Manager> getAll() {
		Session session = sessionFactory.getCurrentSession();	
		Query query  = session.createQuery("from Manager");
		return query.list();
	}
	
	@Override
	public Manager getManagerByRoleIdAndUserId(String roleId, String userId) {
		Session session = sessionFactory.getCurrentSession();	
		Query query  = session.createSQLQuery("	select * from euc_user_role where role_id = ? and user_id = ?").addEntity(Manager.class);
		query.setParameter(0, roleId);
		query.setParameter(1, userId);
		return (Manager) query.uniqueResult();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Manager> getManagerByManagerName(String managerName) {
		Session session = sessionFactory.getCurrentSession();	
		Query query  = session.createQuery("from Manager as a where a.managerName like ?");
		query.setParameter(1, "%"+managerName+"%");
		return query.list();
	}
	
}